{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = np.array([1,2,3])\n",
    "b = np.array([2,2,2])\n",
    "c = np.array([3,1,1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2 3]\n",
      " [2 2 1]\n",
      " [3 2 1]]\n",
      "<class 'numpy.ndarray'>\n"
     ]
    }
   ],
   "source": [
    "matrix = np.column_stack((a,b,c))\n",
    "print(matrix)\n",
    "print(type(matrix))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2 3]\n",
      " [2 2 2]\n",
      " [3 1 1]]\n"
     ]
    }
   ],
   "source": [
    "matrix2 = np.array([a,b,c])\n",
    "print(matrix2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "A = np.array([[2,3],[4,2],[2,2]])\n",
    "B = np.array([[4,2],[4,6]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[20 22]\n",
      " [24 20]\n",
      " [16 16]]\n"
     ]
    }
   ],
   "source": [
    "x = np.dot(A,B)\n",
    "print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "shapes (2,2) and (3,2) not aligned: 2 (dim 1) != 3 (dim 0)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-7-ac89428c1137>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mB\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mA\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m: shapes (2,2) and (3,2) not aligned: 2 (dim 1) != 3 (dim 0)"
     ]
    }
   ],
   "source": [
    "x = np.dot(B,A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2 3]\n",
      " [2 2 1]\n",
      " [3 2 1]]\n",
      "\n",
      "-------------seperation line------------\n",
      "\n",
      "[[ 3.70074342e-17 -1.00000000e+00  1.00000000e+00]\n",
      " [-2.50000000e-01  2.00000000e+00 -1.25000000e+00]\n",
      " [ 5.00000000e-01 -1.00000000e+00  5.00000000e-01]]\n"
     ]
    }
   ],
   "source": [
    "print(matrix)\n",
    "print('\\n-------------seperation line------------\\n')\n",
    "print(np.linalg.inv(matrix))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1.00000000e+00 -6.66133815e-16  3.33066907e-16]\n",
      " [ 0.00000000e+00  1.00000000e+00  1.11022302e-16]\n",
      " [ 0.00000000e+00 -2.22044605e-16  1.00000000e+00]]\n",
      "\n",
      "-------------seperation line------------\n",
      "\n",
      "[[ 1.00000000e+00  0.00000000e+00  1.11022302e-16]\n",
      " [ 0.00000000e+00  1.00000000e+00 -4.44089210e-16]\n",
      " [-1.11022302e-16  0.00000000e+00  1.00000000e+00]]\n"
     ]
    }
   ],
   "source": [
    "inverse = np.linalg.inv(matrix)\n",
    "print(np.dot(matrix,inverse))\n",
    "print('\\n-------------seperation line------------\\n')\n",
    "print(np.dot(inverse,matrix))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 2.]\n",
      " [ 3.]\n",
      " [-1.]]\n"
     ]
    }
   ],
   "source": [
    "A = np.array([[2,1,-1],[-3,-1,2],[-2,1,2]])\n",
    "B = np.array([[8],[-11],[-3]])\n",
    "inv_A = np.linalg.inv(A)\n",
    "print(np.dot(inv_A,B))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 2.]\n",
      " [ 3.]\n",
      " [-1.]]\n"
     ]
    }
   ],
   "source": [
    "print(np.linalg.solve(A,B))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
